<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin extends CI_Controller {

	     public function __construct()
       {
            parent::__construct();
		$this->load->helper("html");
		$this->load->helper("url");
		$this->load->helper('form');
		$this->load->helper('date');
		$this->load->model("admin_model");
		//$this->load->model("guest_comment_model");
		//$this->load->model("news_events_model");
		//$this->load->model("roomcottages_model");
		$this->load->helper(array('form', 'url'));
		$this->load->database();
		
	}
	
	//START ------------------Brocker / Customer---------------------
	function index()
	{
		$data['title']="Administrator Page";
		$data["driver_vendor_data"] = $this->admin_model->admin_all_driver_vendor();
		//$data["guest_comment_data"] = $this->admin_model->admin_all_comment();
		$this->load->view('admin_view',$data);
	}
	function view_driver_vendor()
	{
		$data['title']="Administrator Page";
		$code = $this->uri->segment(3);
		$data["driver_vendor_data"] = $this->admin_model->admin_view_driver_vendor($code);
		$this->load->view('admin_view',$data);
	}
	function edit_driver_vendor()
	{
		$code = $this->uri->segment(3);
		$data['driver_vendor_data'] = $this->admin_model->admin_edit_driver_vendor($code);
		$this->load->view('admin_view',$data);
	}
	function p_edit_driver_vendor()
	{
		$this->load->database();
		$code = $this->uri->segment(3);
		if(isset($_POST['cmdupdate']))
		{
			$profile_type = $_POST['txtprofile_type'];
			$priority_code = $_POST['txtpriority_code'];
			$bc_company_name = $_POST['txtbc_company_name'];
			$n_name = $_POST['txtn_name'];
			$f_name = $_POST['txtf_name'];
			$l_name = $_POST['txtl_name'];
			$cell_phone_num = $_POST['txtcell_phone_num'];
			$office_phone_num  = $_POST['txtoffice_phone_num'];
			$email_add = $_POST['txtemail_add'];
			$trailer_num = $_POST['txttrailer_num'];
			$truck_num = $_POST['txttruck_num'];
			$mc_num = $_POST['txtmc_num'];
		//	$comment_box = $_POST['txtcomment_box'];
			
			$query = $this->db->query("UPDATE profile SET profile_type='".$profile_type."',
												  		  priority_code='".$priority_code."',
														  bc_company_name='".$bc_company_name."', 
														  bc_n_name='".$bc_n_name."',
														  f_name='".$f_name."',
														  l_name='".$l_name."',
														  cell_phone_num='".$cell_phone_num."',
														  office_phone_num='".$office_phone_num."',
														  email_add='".$email_add."',
														  trailer_num='".$trailer_num."',
														  truck_num='".$truck_num."',																												  
														  mc_num='".$mc_num."' "); 			
			if
			($query){$data['recordflag']="<table><tr><td><img src='".base_url()."images/icons/success.gif' /></td><td>Successfully Updated.</td></tr></table>";}
			else
			{
				$data['recordflag']="<table><tr><td><img src='".base_url()."images/icons/error.gif' /></td><td>Error on Saving Data.</td></tr></table>";
			}
		}
		if(isset($_POST['cmdcancel']))
		{
			
		}
		
		
		$data["driver_vendor_data"] = $this->admin_model->admin_all_driver_vendor();		
		$this->load->view('admin_view',$data);
	}
	function add_view_driver_vendor()
	{
		$data["driver_vendor_data"] = $this->admin_model->add_view_driver_vendor();
		$this->load->view('admin_view',$data);
	}
	function p_add_driver_vendor()
	{
		
		$this->load->database();
		if(isset($_POST['cmdsave']))
		{
			$profile_type =$_POST['txtprofile_type'];
			$priority_code =$_POST['txtpriority_code'];
			$bc_company_name =$_POST['txtbc_company_name'];
			$bc_n_name =$_POST['txtbc_n_name'];
			$f_name =$_POST['txtf_name'];
			$l_name =$_POST['txtl_name'];
			$cell_phone_num =$_POST['txtcell_phone_num'];
			$office_phone_num =$_POST['txtoffice_phone_num'];
			$email_add =$_POST['txtemail_add'];
			$trailer_num =$_POST['txttrailer_num'];
			$truck_num =$_POST['txttruck_num'];			
			$mc_num =$_POST['txtmc_num'];
			$comment_box =$_POST['txtcomment_box'];
											 
			$_sql="insert into profile(profile_id,profile_type,priority_code,bc_company_name,bc_n_name,f_name,l_name,cell_phone_num,office_phone_num,email_add,trailer_num,truck_num,mc_num,comment_box)";
			$_sql.="values(null,'".$profile_type."','".$priority_code."','".$bc_company_name."','".$bc_n_name."','".$f_name."','".$l_name."','".$cell_phone_num."','".$office_phone_num."','".$email_add."','".$trailer_num."','".$truck_num."','".$mc_num."','".$comment_box."')";
			$query = $this->db->query($_sql); 
			if($query){$data['recordflag']="<table><tr><td><img src='".base_url()."images/icons/success.gif' /></td><td>Successfully Added.</td></tr></table>";}else{$data['recordflag']="<table><tr><td><img src='".base_url()."images/icons/error.gif' /></td><td>Error on Saving Data.</td></tr></table>";}
		}
		if(isset($_POST['cmdcancel']))
		{
			
		}
				
		$data["driver_vendor_data"] = $this->admin_model->admin_all_driver_vendor();		
		$this->load->view('admin_view',$data);
					
	}
	function delete_driver_vendor()
	{
		$this->load->database();
		
		$code = $this->uri->segment(3);
		if(isset($_POST['cmdyes']))
		{
			$query = $this->db->query("delete from profile where profile_id='$code'");
			if($query){$data['recordflag']="<table><tr><td><img src='".base_url()."images/icons/success.gif' /></td><td>Successfully Deleted.</td></tr></table>";}else{$data['recordflag']="<table><tr><td><img src='".base_url()."images/icons/error.gif' /></td><td>Unable to Delete Data.</td></tr></table>";}
		}
		else
		{
			$data['recordflag'] = "	<div align='left'>
										<table>
											<tr>
												<td><img src='".base_url()."images/icons/error.gif' /></td>
												<td><b>Do You Want to Delete this Record?</b></td>
											</tr>
										</table>
									</div>
									<div align='right'>
										<form method='post' action='".base_url()."admin/delete_driver_vendor/".$code."'>
											<table>
												<tr>
													<td>
														<input type='submit' name='cmdyes' value='Yes' style='background-image:url(".base_url()."images/icons/check.png);
		background-position:left;background-color:transparent;background-repeat:no-repeat;text-align:right;width:55px;border:none transparent;color:#0000FF' />					</td>
													<td></td>
													<td>
														<input type='submit' name='cmdno' value='No' style='background-image:url(".base_url()."images/icons/action_delete.gif);
		background-position:left;background-color:transparent;background-repeat:no-repeat;text-align:right;width:50px;border:none transparent;color:#0000FF' />					</td>
												</tr>
											</table>
										</form>
									</div>";
			
		}
		if(isset($_POST['cmdno']))
		{
			$data['recordflag'] = "";
			
		}
		
		$data["driver_vendor_data"] = $this->admin_model->admin_all_driver_vendor();	
		$this->load->view('admin_view',$data);
		
	}
	//END ------------------------NEWS------------------
	
	function logout()
	{
		
		//$this->load->library('session');
		//$this->session->sess_destroy();
		session_start();
		session_destroy();
		//echo $_SESSION['administrator_log'];
		//unset($_SESSION['administrator_log']);
		
			//$this->session->unset_userdata('administrator_log');
			$data["newsresult"] = $this->admin_model->admin_all_driver_vendor();
			//$data["guest_comment_data"] = $this->guest_comment_model->guest_comment_summary();
			//$data["rates"] = $this->roomcottages_model->rates();
			$this->load->view('admin_view',$data);
		
		 
	}
	
 
}
?>